Personal tools

Lua/Client/ClientLight/Static Functions/Create

From JC2-MP Documentation

< Lua‎ | Client‎ | ClientLight
Jump to: navigation, search

Returns    ClientLight
Prototype    ClientLight.Create(table arguments)
Description    No description


Argument table

Required values

Type Name Notes
Vector3 position
Color color

Optional values

Type Name Default Notes
number multiplier 1 The brightness. Values are between 0 and 10.
number radius 2
number constant_attenuation 1 See here. (Does not appear to affect anything.)
number linear_attenuation 0.1 See here (Does not appear to affect anything.)
number quadratic_attenuation 0.01 See here (Does not appear to affect anything.)
number fade_in_duration 0.2
number fade_out_duration 0.2

Examples

Spawn a light where you click

  1. lights = {}
  2.  
  3. Events:Subscribe("MouseDown", function(args)
  4. 	if args.button ~= 1 then
  5. 		return
  6. 	end
  7.  
  8. 	local result = Physics:Raycast(
  9. 		Camera:GetPosition(),
  10. 		Camera:GetAngle() * Vector3.Forward,
  11. 		0,
  12. 		100
  13. 	)
  14.  
  15. 	local light = ClientLight.Create{
  16. 		position = result.position + result.normal * 1.5,
  17. 		color = Color.FromHSV(math.random(1, 360), 1, 1),
  18. 		constant_attenuation = 0,
  19. 		linear_attenuation = 0,
  20. 		quadratic_attenuation = 1,
  21. 		multiplier = 3.0,
  22. 		radius = 15.0,
  23. 	}
  24.  
  25. 	table.insert(lights, light)
  26. end)
  27.  
  28. -- Make sure to clean up all of our lights on ModuleUnload.
  29. Events:Subscribe("ModuleUnload", function()
  30. 	for index, light in ipairs(lights) do
  31. 		light:Remove()
  32. 	end
  33. end)